package controller

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"my-blog/main/dao"
	"my-blog/main/session"
	"net/http"
	"strconv"
)

func HomeController(c *gin.Context) {
	page := c.Query("page")
	cid := c.Query("cid")
	if cid == "" {
		cid = "1"
	}
	id, _ := strconv.Atoi(cid)

	articleClass, count, currentPage, shortArticleList := dao.GetArticleClassAndShortArticleList(dao.Dbdao, page, id)
	head := map[string]interface{}{"active": "index"}
	c.HTML(http.StatusOK, "index.html", gin.H{
		"head":         head,
		"articleClass": articleClass,
		"count":        count,
		"cid":          id,
		"sArticle":     shortArticleList,
		"currentPage":  currentPage,
	})
}

func AboutController(c *gin.Context) {
	get := session.SessionUtils.Get(c)
	if get != nil {
		fmt.Println(get.Get("t"))
		fmt.Println(get.Get("a"))
	}
	head := map[string]interface{}{"active": "about"}
	c.HTML(http.StatusOK, "about.html", gin.H{
		"head": head,
	})
}

func AlbumController(c *gin.Context) {
	head := map[string]interface{}{"active": "album"}
	c.HTML(http.StatusOK, "album.html", gin.H{
		"head": head,
	})
}

func WhisperController(c *gin.Context) {
	head := map[string]interface{}{"active": "whisper"}
	c.HTML(http.StatusOK, "whisper.html", gin.H{
		"head": head,
	})
}

func MessageController(c *gin.Context) {
	head := map[string]interface{}{"active": "message"}
	c.HTML(http.StatusOK, "message.html", gin.H{
		"head": head,
	})
}

func DetailsController(c *gin.Context) {
	c.HTML(http.StatusOK, "details.html", gin.H{
		"title": "你好",
	})
}
